package com.androidtv.pos.ui.fragment;

import android.os.Bundle;
import android.view.View;

import com.androidhelper.module.common.base.BaseFragment;
import com.androidtv.pos.R;
import com.flyco.tablayout.SegmentTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;

public class RightMainFragment extends BaseFragment {


    @BindView(R.id.segmentTavLayout)
    SegmentTabLayout segmentTavLayout;

    @BindView(R.id.viewPager)
    ViewPager viewPager;

      String[] mTitlesTabArr = {"早餐", "午餐", "晚餐"};

    List<BaseFragment> mFragmentList;



    public static RightMainFragment newInstance() {
        Bundle args = new Bundle();
        RightMainFragment fragment = new RightMainFragment();
        fragment.setArguments(args);
        return fragment;
    }



    @Override
    protected int attachLayoutRes() {
        return R.layout.fragment_main_right;
    }

    @Override
    protected void initView(View view, @Nullable Bundle savedInstanceState) {
         mFragmentList = new ArrayList<>();
         for(int i=0;i<mTitlesTabArr.length;i++){
          //  mFragmentList.add(MealFragment.newInstance(i,mTitlesTabArr[i]));
        }




      //  viewPager.setAdapter( new RightMainFragmentPagerAdapter(getChildFragmentManager(),mFragmentList,mTitlesTabArr));
        segmentTavLayout.setTabData(mTitlesTabArr);
        viewPager.setOffscreenPageLimit(3);
        viewPager.setCurrentItem(0);

        segmentTavLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                viewPager.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });



        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                segmentTavLayout.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });



    }









    @Override
    protected void setListener() {

    }

    @Override
    protected void initEventAndData(Bundle savedInstanceState) {

    }
}
